
object IPV4HeaderChecker {
  def checksum(header: String): String = {
    val array = header.split(" ")
    val _hexStr = Integer.toHexString(array.map { x => Integer.parseInt(x, 16) }.sum)
    val hexStr = _hexStr.length() match {
      case 5 => Integer.toHexString(Integer.parseInt(_hexStr.tail, 16) + Integer.parseInt(_hexStr.take(1), 16))
      case _ => _hexStr
    }

    array(5) = Integer.toHexString(Integer.parseInt("ffff", 16) - Integer.parseInt(hexStr, 16))
    array.mkString(" ")
  }
}
